package com.power.controller;

import com.alibaba.fastjson.JSON;
import com.power.ov.ResultData;
import com.power.ov.ResultDataTable;
import com.power.service.TowerService;
import com.power.service.impl.TowerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: 李辽
 * Date: 2020/10/04 12:21
 * Description:通过杆塔编号删除当前行的杆塔信息
 * Version: V1.0
 */
@WebServlet("/deletetower.do")
public class DeleteTower extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取删除当前行的杆塔编号
        int towper_id = Integer.parseInt(request.getParameter("towper_id"));
        ResultDataTable resultData = new ResultDataTable();
        TowerService towerService = new TowerServiceImpl();

        response.setContentType("application/json;charset=utf-8");
        int result = 0;
        try {
            result = towerService.DeleteTowerByName(towper_id);
            if (result > 0){
                resultData.setCode(200);
                resultData.setMessage("删除成功！！！");
                resultData.setData(result);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            resultData.setCode(500);
            resultData.setMessage("删除失败！！！");
            resultData.setData(result);
        }
            response.getWriter().write(JSON.toJSONString(resultData));
            response.getWriter().flush();
            response.getWriter().close();
    }
}
